#include<iostream>
#include <string>
using namespace std;
class Solution {
public:
    bool isMatch(string s, string p) {
        bool dp[500][500];
        memset(dp, 0, sizeof dp);
        dp[0][0] = 1;
        for (int i = 0; i < p.length(); i++) 
        {
            if (p[i] == '*') 
            {
                dp[0][i + 1] = dp[0][i - 1];
            }
            else 
            {
                dp[0][i + 1] = 0;
            }
        }
        for (int i = 0; i < s.length(); i++)
        {
            for (int j = 0; j < p.length(); j++)
            {
                if (s[i] == p[j] || p[j] == '.')
                {
                    dp[i + 1][j + 1] = dp[i][j];
                    continue;
                }
                if (p[j] == '*')
                {
                    if (p[j - 1] != '.' && p[j - 1] != s[i])
                    {
                        dp[i + 1][j + 1] = dp[i+1][j-1];
                        continue;
                    }
                    else
                    {
                        dp[i + 1][j + 1] = (dp[i + 1][j] || dp[i][j + 1] || dp[i + 1][j - 1]);
                        continue;
                    }
                }
            }
        }
        return dp[s.length()][p.length()];
    }
};
int main()
{
    Solution s;
    string ss = "aa", pp = "a";
    while(cin>>ss>>pp)
    if(s.isMatch(ss, pp))
        cout << 1 << endl;
    else
        cout << 0 << endl;
}